package com.biscuit.page.basicservice.model.exception;

import com.biscuit.page.basicservice.model.enums.BaseResponseEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author mazihao
 * @createTime 2024/3/7 17:18
 */
@Getter
public class BaseException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = -2037682411981919795L;

    private final String code;

    private final String message;

    public BaseException() {
        super(BaseResponseEnum.ERROR_PARAM.getMessage());
        this.code = BaseResponseEnum.ERROR_PARAM.getCode();
        this.message = BaseResponseEnum.ERROR_PARAM.getMessage();
    }

    public BaseException(String message) {
        super(message);
        this.code = BaseResponseEnum.ERROR_PARAM.getCode();
        this.message = StringUtils.isNotBlank(message) ? message : BaseResponseEnum.ERROR_PARAM.getMessage();
    }

    public BaseException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BaseException(BaseResponseEnum baseResponseEnum) {
        this(baseResponseEnum.getCode(), baseResponseEnum.getMessage());
    }

}
